using UnityEngine;
using System.Collections.Generic;
using System.Collections;
using System;

using BaseLib;

public enum TickerStatus
{
	 /// Animator is in playing.
	 TICKING = 0,	 
	/// Animator is paused.
	 PUASED,	 
	 /// Animator is stopped.
	 STOPPED,
}

public struct TickableType
{
    public static int DEFAULT = 0;

    public static int Pooled = 0x1 << 0;
}

abstract public class Tickable : RefCounter
{
    /// Current animator's status, see AnimatorStatus for details.
    public TickerStatus status { get {return _status; } }

    public void _MarkType(int type) { _Type |= type; }
	public int _Type;
	protected TickerStatus _status;

    protected bool _bDisposed;
    //-------- Internal property --------------
    public int _QueueIndex;

    public bool _IsDead;
    public bool _Scalable;


	public Tickable()
	{
		_IsDead = false;
		_QueueIndex = -1;
		
		_bDisposed = false;		
		_status = TickerStatus.STOPPED;
		
		_Type = TickableType.DEFAULT;

        _Scalable = true;
	}

	/**
	 * @param	nDeltaTime 
	 * @return	return true if this tickable object is dead, or else false.
	 */
    abstract public void _Tick(float fTime);

	virtual public void Pause()
	{
        if (_status != TickerStatus.TICKING) return;

		Debugger.Assert(!IsDisposed());
		_status = TickerStatus.PUASED;
	}

    virtual public void Resume()
	{
        Debugger.Assert(!IsDisposed());

        if (_status != TickerStatus.PUASED) return;
		_status = TickerStatus.TICKING;
	}

	//----------------- Internal methods -----------------------------------
	/// Performs application-defined tasks associated with freeing, releasing, or resetting resources. 
	virtual public void Dispose()
	{
		Debugger.Assert(status == TickerStatus.STOPPED, "Must stop a Tickable before dispose it!!!");
		_bDisposed = true;
	}
	
	/// Check if an object is disposed.
	virtual public bool IsDisposed()
	{
		return _bDisposed == true;
	}
		
	public void _SetStatus(TickerStatus newStatus)
	{
		_status = newStatus;
	}

    public bool _isType(int type)
    {
        return (_Type & type) != 0;
    }

}
